package darknet.application.chat.impl.net.message;

import darknet.core.impl.net.AbstractMessage;
import darknet.core.spec.net.MessageHeader;
import darknet.core.spec.net.Node;

/**
 * An exit channel message.
 *
 * This message is sent by a connected node to the channel owner to notify him
 * he has just exit the channel.
 *
 * The channel owner must remove him from the list of connected nodes.
 *
 * @author yoyo
 */
public class ExitChannelMessage extends AbstractMessage {
    
    /** The channel name */
    private String channelName;

    /**
     * Initialise a new Exit Channel Message.
     * 
     * @param from The writer
     * @param to   The receiver
     * @param channelName The channel name
     */
    public ExitChannelMessage(MessageHeader header, Node from, Node to,
            String channelName) {

	super(header, from, to);
	
	if (channelName == null || channelName.length() == 0) {
	    throw new IllegalArgumentException("channelName is invalid");
	}
	this.channelName = channelName;
    }

    /**
     * Get the channel name.
     * @return
     */
    public String getChannelName() {
	return channelName;
    }

    @Override
    public String toString() {

        StringBuilder builder = new StringBuilder("ExitChannelMessage[");
        builder.append("super=");
        builder.append(super.toString());
        builder.append(", ");
        builder.append("channelName=");
        builder.append(channelName);
        builder.append("]");

        return builder.toString();
    }
}
